/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FramePrincipal.java
 *
 * Created on 11/11/2010, 21:50:35
 */

package Interface;

import Controle.Controle;
import java.awt.Cursor;
import java.awt.Toolkit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author Linton
 */
public class FramePrincipal extends javax.swing.JFrame {
 Controle controle = new Controle();
 public int limiar=-1;
// TelaImagem telaImagemOriginal;
// TelaImagem telaImagemAlterada;

    /** Creates new form FramePrincipal */
    public FramePrincipal() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(FramePrincipal.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(FramePrincipal.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(FramePrincipal.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(FramePrincipal.class.getName()).log(Level.SEVERE, null, ex);
        }
        initComponents();
        histograma.setEnabled(false);
        equalizar.setEnabled(false);
        watershed.setEnabled(false);
      //  limpar.setEnabled(false);
        salvar.setEnabled(false);
        pontos.setEnabled(false);
        gradiente.setEnabled(false);
        binarizar.setEnabled(false);
        voltar.setEnabled(false);
        refazer.setEnabled(false);
        skiz.setEnabled(false);
        contorno.setEnabled(false);
        recortar.setEnabled(false);

        
        double width = Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2;
        double widthf = getWidth() / 2;
        double heigthf = getHeight();
        System.out.println(heigthf);
        int widthFinal = (int) (width - widthf);
        int heigthFinal = (int) (10);
        setLocation(widthFinal, heigthFinal);
    }

     public void acaoBotoesAbrir(){
        histograma.setEnabled(true);
        equalizar.setEnabled(true);
        watershed.setEnabled(true);
        //limpar.setEnabled(true);
        salvar.setEnabled(true);
        pontos.setEnabled(true);
         gradiente.setEnabled(true);
        binarizar.setEnabled(true);
        voltar.setEnabled(true);
        refazer.setEnabled(true);
        skiz.setEnabled(true);
        contorno.setEnabled(true);
        recortar.setEnabled(true);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jToolBar1 = new javax.swing.JToolBar();
        abrir = new javax.swing.JButton();
        salvar = new javax.swing.JButton();
        recortar = new javax.swing.JButton();
        voltar = new javax.swing.JButton();
        refazer = new javax.swing.JButton();
        histograma = new javax.swing.JButton();
        equalizar = new javax.swing.JButton();
        gradiente = new javax.swing.JButton();
        binarizar = new javax.swing.JButton();
        watershed = new javax.swing.JButton();
        pontos = new javax.swing.JButton();
        contorno = new javax.swing.JButton();
        skiz = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        sair = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jToolBar1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jToolBar1.setFloatable(false);

        abrir.setBackground(new java.awt.Color(244, 244, 244));
        abrir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/Open-icon.png"))); // NOI18N
        abrir.setText("Abrir");
        abrir.setFocusable(false);
        abrir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        abrir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        abrir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                abrirActionPerformed(evt);
            }
        });
        jToolBar1.add(abrir);

        salvar.setBackground(new java.awt.Color(244, 244, 244));
        salvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/Save_64.png"))); // NOI18N
        salvar.setText("Salvar");
        salvar.setFocusable(false);
        salvar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        salvar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        salvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvarActionPerformed(evt);
            }
        });
        jToolBar1.add(salvar);

        recortar.setBackground(new java.awt.Color(244, 244, 244));
        recortar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/recortar.png"))); // NOI18N
        recortar.setText("Recortar");
        recortar.setFocusable(false);
        recortar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        recortar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        recortar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                recortarActionPerformed(evt);
            }
        });
        jToolBar1.add(recortar);

        voltar.setBackground(new java.awt.Color(244, 244, 244));
        voltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/Undo-256.png"))); // NOI18N
        voltar.setText("Voltar");
        voltar.setFocusable(false);
        voltar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        voltar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        voltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                voltarActionPerformed(evt);
            }
        });
        jToolBar1.add(voltar);

        refazer.setBackground(new java.awt.Color(244, 244, 244));
        refazer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/Redo-256.png"))); // NOI18N
        refazer.setText("Refazer");
        refazer.setFocusable(false);
        refazer.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        refazer.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        refazer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                refazerActionPerformed(evt);
            }
        });
        jToolBar1.add(refazer);

        histograma.setBackground(new java.awt.Color(244, 244, 244));
        histograma.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/histograma.png"))); // NOI18N
        histograma.setText("Histograma");
        histograma.setFocusable(false);
        histograma.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        histograma.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        histograma.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                histogramaActionPerformed(evt);
            }
        });
        jToolBar1.add(histograma);

        equalizar.setBackground(new java.awt.Color(244, 244, 244));
        equalizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/equalizer.png"))); // NOI18N
        equalizar.setText("Equalizar");
        equalizar.setFocusable(false);
        equalizar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        equalizar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        equalizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                equalizarActionPerformed(evt);
            }
        });
        jToolBar1.add(equalizar);

        gradiente.setBackground(new java.awt.Color(244, 244, 244));
        gradiente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/lena 256x256.png"))); // NOI18N
        gradiente.setText("Gradiente");
        gradiente.setFocusable(false);
        gradiente.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        gradiente.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        gradiente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                gradienteActionPerformed(evt);
            }
        });
        jToolBar1.add(gradiente);

        binarizar.setBackground(new java.awt.Color(244, 244, 244));
        binarizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/tabuleiro1.png"))); // NOI18N
        binarizar.setText("Binarizar");
        binarizar.setFocusable(false);
        binarizar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        binarizar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        binarizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                binarizarActionPerformed(evt);
            }
        });
        jToolBar1.add(binarizar);

        watershed.setBackground(new java.awt.Color(244, 244, 244));
        watershed.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/Watershed_Bowls_with text_TCEQ.png"))); // NOI18N
        watershed.setText("Watershed");
        watershed.setFocusable(false);
        watershed.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        watershed.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        watershed.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                watershedActionPerformed(evt);
            }
        });
        jToolBar1.add(watershed);

        pontos.setBackground(new java.awt.Color(244, 244, 244));
        pontos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/pontos.png"))); // NOI18N
        pontos.setText("Pontos");
        pontos.setFocusable(false);
        pontos.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        pontos.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        pontos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pontosActionPerformed(evt);
            }
        });
        jToolBar1.add(pontos);

        contorno.setBackground(new java.awt.Color(244, 244, 244));
        contorno.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/contorno.png"))); // NOI18N
        contorno.setText("Contorno");
        contorno.setFocusable(false);
        contorno.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        contorno.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        contorno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                contornoActionPerformed(evt);
            }
        });
        jToolBar1.add(contorno);

        skiz.setBackground(new java.awt.Color(244, 244, 244));
        skiz.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/skiz.png"))); // NOI18N
        skiz.setText("Skiz");
        skiz.setFocusable(false);
        skiz.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        skiz.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        skiz.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                skizActionPerformed(evt);
            }
        });
        jToolBar1.add(skiz);

        jButton1.setBackground(new java.awt.Color(244, 244, 244));
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/configure-256.png"))); // NOI18N
        jButton1.setText("Configurar");
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton1);

        sair.setBackground(new java.awt.Color(244, 244, 244));
        sair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/Close-64.png"))); // NOI18N
        sair.setText("Sair");
        sair.setFocusable(false);
        sair.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        sair.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        sair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sairActionPerformed(evt);
            }
        });
        jToolBar1.add(sair);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void abrirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_abrirActionPerformed
        // TODO add your handling code here:
        
        controle.abrirImagem();
        this.acaoBotoesAbrir();
    }//GEN-LAST:event_abrirActionPerformed

    private void salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvarActionPerformed
        // TODO add your handling code here:
         controle.salvarImagem();
    }//GEN-LAST:event_salvarActionPerformed

    private void voltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_voltarActionPerformed
        // TODO add your handling code here:
        controle.desfazer();
    }//GEN-LAST:event_voltarActionPerformed

    private void refazerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refazerActionPerformed
        // TODO add your handling code here:
        controle.refazer();
    }//GEN-LAST:event_refazerActionPerformed

    private void binarizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_binarizarActionPerformed
        // TODO add your handling code here:
        controle.binarizar(this.limiar);//binarizar();
    }//GEN-LAST:event_binarizarActionPerformed

    private void histogramaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_histogramaActionPerformed
        // TODO add your handling code here:
        controle.gerarHistograma();
    }//GEN-LAST:event_histogramaActionPerformed

    private void equalizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_equalizarActionPerformed
        // TODO add your handling code here:
        controle.equalizar();
    }//GEN-LAST:event_equalizarActionPerformed

    private void gradienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gradienteActionPerformed
        // TODO add your handling code here:
        controle.gradiente();
    }//GEN-LAST:event_gradienteActionPerformed

    private void pontosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pontosActionPerformed
        // TODO add your handling code here:
        controle.buscarPontosBrilhantes();
        //controle.inserirContorno();
    }//GEN-LAST:event_pontosActionPerformed

    private void watershedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_watershedActionPerformed
        // TODO add your handling code here:
        controle.segmentar();
    }//GEN-LAST:event_watershedActionPerformed

    private void sairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sairActionPerformed
        // TODO add your handling code here:
       System.exit(1);
    }//GEN-LAST:event_sairActionPerformed

    private void skizActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_skizActionPerformed
        // TODO add your handling code here:
        controle.skiz();
    }//GEN-LAST:event_skizActionPerformed

    private void contornoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_contornoActionPerformed
        // TODO add your handling code here:
        controle.equalizar();
        controle.binarizar(this.limiar);
        controle.gradiente();
        controle.binarizar(this.limiar);
        controle.inserirContorno();
    }//GEN-LAST:event_contornoActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        getLimiar();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void recortarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_recortarActionPerformed
        // TODO add your handling code here:
        controle.setRecortar(true);
    }//GEN-LAST:event_recortarActionPerformed

    public int getLimiar(){
        TelaConfiguracaoLimiar tela = new TelaConfiguracaoLimiar();
        tela.setTelaPrincipal(this);
        tela.setVisible(true);
        return this.limiar;
    }
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FramePrincipal().setVisible(true);
            }
        });
    }

    public void setLimiar(int limiar) {
        this.limiar = limiar;
    }

    public int getLimiarFrame(){
        return this.limiar;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton abrir;
    private javax.swing.JButton binarizar;
    private javax.swing.JButton contorno;
    private javax.swing.JButton equalizar;
    private javax.swing.JButton gradiente;
    private javax.swing.JButton histograma;
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JButton pontos;
    private javax.swing.JButton recortar;
    private javax.swing.JButton refazer;
    private javax.swing.JButton sair;
    private javax.swing.JButton salvar;
    private javax.swing.JButton skiz;
    private javax.swing.JButton voltar;
    private javax.swing.JButton watershed;
    // End of variables declaration//GEN-END:variables

}
